<?php

namespace JsonLowCode\UI;

use Closure;
use JsonLowCode\Schema;
use JsonLowCode\Traits\Props\HasBordered;
use JsonLowCode\Traits\Slots\HasSlotFooter;
use JsonLowCode\Traits\Slots\HasSlotHeader;

/**
 * NList组件
 * @method static NList make(mixed $children = null) Thing组件
 */
class NList extends Schema
{
    protected string $componentName = "NList";

    use HasBordered;
    use HasSlotHeader, HasSlotFooter;

    /**
     * @param mixed|null $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $this->children($children);
    }

    /**
     * 设置组件列表项是否有可点击样式
     * @param bool|string $bool
     * @return $this
     */
    public function clickable(bool|string $bool = true): static
    {
        return $this->prop('clickable', $bool);
    }

    /**
     * 列表项是否有悬浮样式
     * @param bool|string $bool
     * @return $this
     */
    public function hoverable(bool|string $bool = true): static
    {
        return $this->prop('hoverable', $bool);
    }

    /**
     * 是否显示标项之间的分割线
     * @param bool|string $bool
     * @return $this
     */
    public function showDivider(bool|string $bool = true): static
    {
        return $this->prop('show-divider', $bool);
    }

    /**
     * @param NListItem|Closure $item
     * @return $this
     */
    public function item(NListItem|Closure $item): static
    {
        if ($item instanceof NListItem){
            $this->children($item);
        }
        if ($item instanceof Closure){
            $element = new NListItem($item);
            $this->children($element);
        }
        return $this;
    }
}
